home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softwarová Záchrana 3
/
Softwarova-zachrana-3.bin
/
TextHarvest
/
TextHarvest-Install.exe
/
{app}
/
ScrExercise.txt
< prev
next >
Wrap
Text File
|
2005-02-22
|
73KB
|
2,060 lines
;===============================================================================
; The Exercise Script
;===============================================================================
;
; This is the actual script used by Pinnacle Software to verify that
; the Parse-O-Matic Scripting commands are working properly. We run
; this script after we make changes to the Parsing or Scripting engines,
; to ensure that the commands are still functioning correctly.
;
; To try out this script, use any text input file -- it only reads the
; first line. The output (when everything is working fine) is simply
; a tidy list of scripting commands and concepts.
;
; You can refer to this file if you are ever in doubt about the way
; that a command should be used.
;
;===============================================================================
; Config
;===============================================================================
Config
$CfgEnableOptionX = 'N'
$CfgEnableOptionY = 'N'
$CfgCaptionZ = '&Test flag'
$CfgHintZ = 'Leave blank - see Help for explanation'
$CfgCopyright = 'Copyright ⌐ 2003, 2005 by Pinnacle Software'
$CfgVersion = '2.00.00'
$CfgProgrammer = 'Timothy Campbell'
$CfgEmail = 'info@parse-o-matic.com'
$CfgLicense = 'This script may be used, at no charge, with any ' >>
'script-enabled Parse-O-Matic application, subject to any additional ' >>
'licensing requirements of such application.'
$CfgDefaultIFN = 'ThingsToDoUnix.txt';
$CfgDefaultOFN = 'Temp.txt';
End
;===============================================================================
; TaskInit
;===============================================================================
TaskInit
;-----------------------------------------------------------------------------
; Check to see if /NI is in OptionZ. If so, we suppress most of the
; informational output. This parameter is used for internal testing at
; Pinnacle Software and may change from version to version of this script.
; Under normal circumstances, variable PT ("Pinnacle Test") is set to 'N'.
;-----------------------------------------------------------------------------
TestOptZ = $OptionZ
PT = 'N'
TestOptZ = ChangeCase TestOptZ
Begin TestOptZ ^ '/NI'
PT = 'Y'
Change TestOptZ '/NI' ''
End
;-----------------------------------------------------------------------------
; Make sure all the option boxes are empty
;-----------------------------------------------------------------------------
Call EnsureOptionEmpty $CaptionZ #13 TestOptZ
OutEnd '.ùùùùùùùùùùùùùùù.'
OutEnd '| EXERCISE |'
OutEnd '+ùùùùùùùùùùùùùùù+'
OutEnd '| TaskInit |'
;-----------------------------------------------------------------------------
; This next demonstration uses Done to leave this section and move on to
; the next step (i.e. FileInit). In an actual script, though, it would be
; pointless to have an unconditional Done in the TaskInit section. You
; normally leave a step for a reason, or simply let the code run on until
; its final End statement.
; Note that "Done", when used in the Main step, is not equivalent to
; NextStep. The "Flow Control" section of the Parse-O-Matic Scripting
; manual explains this in more detail.
;-----------------------------------------------------------------------------
Done ; Leave this section
OutEnd 'This line will not appear' ; This line won't show up in output
End
;===============================================================================
; FileInit
;===============================================================================
FileInit
OutEnd '| FileInit |'
OutEnd '+ ù ù ù ù ù ù ù +'
;-----------------------------------------------------------------------------
; This next demonstration uses NextStep to leave this section and move on
; to the next step (i.e. Main). In an actual script, though, it would be
; pointless to have an unconditional NextStep in the FileInit section.
; You normally leave a step for a reason, or simply let the code run on
; until its final End statement.
;-----------------------------------------------------------------------------
NextStep ; Leave this section
OutEnd 'This line will not appear' ; This line won't show up in output
End
;===============================================================================
; FileDone
;===============================================================================
FileDone
OutEnd '+ ù ù ù ù ù ù ù +'
OutEnd '| FileDone |'
End
;===============================================================================
; TaskDone
;===============================================================================
TaskDone
OutEnd '| TaskDone |'
OutEnd '|ùùùùùùùùùùùùùùù|'
OutEnd '| FINISHED |'
OutEnd '''ùùùùùùùùùùùùùùù'''
End
;===============================================================================
; The Again Command (see "The Begin/Else/End/Again Commands" for tests)
;===============================================================================
If PT = 'N' OutEnd '| Again |' ; Included here for completeness
;===============================================================================
; AlphaNumPatt
;===============================================================================
If PT = 'N' Output '| AlphaNumPatt |'
Z = '1234-Ba/9'
X = AlphaNumPatt Z ; Generate the pattern
If X <> 'NNNN-AA/N' Odb 'A' X
Z = '#AbA-33:4'
X = AlphaNumPatt Z ; Different layout
If X <> '#AAA-NN:N' Odb 'B' X
Z = ' @XYZ-99:9 ' ; Note the spaces on either side
X = AlphaNumPatt Z
If X <> ' @AAA-NN:N ' Odb 'C' X
Z = ' %A9-CD-99 '
X = AlphaNumPatt Z 'B ' ; Trim spaces on both sides
If X <> '%AN-AA-NN' Odb 'D' X
Z = ' A2-B3-D4 '
X = AlphaNumPatt Z 'A A-' ; Trim spaces and dashes
If X <> 'ANANAN' Odb 'E' X
Z = '12-34-56' ; Example from the Help file
X = AlphaNumPatt Z
If X <> 'NN-NN-NN' Odb 'F' X
Z = ' $12.34 ' ; Example from the Help file
X = AlphaNumPatt Z
If X <> ' $NN.NN ' Odb 'G' X
Z = 'AB 1234' ; Example from the Help file
X = AlphaNumPatt Z
If X <> 'AA NNNN' Odb 'H' X
Z = ' XY 999 ' ; Example from the Help file
X = AlphaNumPatt Z 'B '
If X <> 'AA NNN' Odb 'I' X
Z = ' XY 999 '
X = AlphaNumPatt Z 'A '
If X <> 'AANNN' Odb 'J' X
If PT = 'N' OutNull
;===============================================================================
; Arrays
;===============================================================================
If PT = 'N' Output '| Arrays |'
;-------------------------------------------------------------------------------
; First we will demonstrate arrays with numeric indices
;-------------------------------------------------------------------------------
X = 'ABCDE' >> ; Demonstration of line continuation
'FGHIJ' ; We could have done X = 'ABCDEFGHIJ'
Cntr = 0
Begin
Cntr = Cntr+
MyArray(Cntr) = Cols X Cntr Cntr ; Set MyArray(1) through MyArray(6)
Again Cntr #< 6 ; Repeat if we haven't reached 6
MyArray = 'XYZ' ; Has no effect; it's not an array
If MyArray(1) <> 'A' Odb '1A' MyArray(1)
If MyArray(2) <> 'B' Odb '1B' MyArray(2)
If MyArray(3) <> 'C' Odb '1C' MyArray(3)
If MyArray(4) <> 'D' Odb '1D' MyArray(4)
If MyArray(5) <> 'E' Odb '1E' MyArray(5)
If MyArray(6) <> 'F' Odb '1F' MyArray(6)
;-------------------------------------------------------------------------------
; When we inspect an array element that was never assigned a value, it
; returns the special variable $NotDefined, which is usually set to '[ND]'.
; You can set $NotDefined to some other value if you wish.
;-------------------------------------------------------------------------------
Cntr = 7
If MyArray(Cntr) <> $NotDefined Odb '1Z' MyArray(Cntr)
;-------------------------------------------------------------------------------
; A gratuitously complex example of arrays in action
;-------------------------------------------------------------------------------
Jx = 'Test'
Kx = 1
Lx = 3
MyArray(Jx) = 'abcdefghij'
MyArray(Kx) = 2
MyArray(Lx) = 4
MyArray(Lx) = Cols MyArray(Jx) MyArray(Kx) MyArray(Lx)
If MyArray(Jx)[2 3] <> 'bc' Odb '2A' MyArray(Jx)[2 3]
If MyArray(Kx) <> '2' Odb '2B' MyArray(Kx)
If MyArray(Lx) <> 'bcd' Odb '2C' MyArray(Lx)
If Jx <> 'Test' Odb '2D' Jx
If Kx <> 1 Odb '2E' Kx
If Lx <> 3 Odb '2F' Lx
;-------------------------------------------------------------------------------
; Demonstrating arrays with text indices
;-------------------------------------------------------------------------------
TextIndex = 'Cat'
MyArray(TextIndex) = 'Fluffy'
TextIndex = 'Dog'
MyArray(TextIndex) = 'Fido'
If MyArray('Cat') <> 'Fluffy' Odb '4A' MyArray('Cat')
If MyArray('Dog') <> 'Fido' Odb '4B' MyArray('Dog')
;-------------------------------------------------------------------------------
; Demonstrating the use of arrays with a command that alters the variable
;-------------------------------------------------------------------------------
KeepChar MyArray('Dog') '/F/o'
If MyArray('Dog') <> 'Fo' Odb '5' MyArray('Dog')
;-------------------------------------------------------------------------------
; The variable named MyArray was set earlier. It does not have any effect on
; the arrays because it does not look like an array (i.e. the name is not
; followed by an index in parentheses).
;-------------------------------------------------------------------------------
If MyArray <> 'XYZ' Odb 'Z' MyArray ; Variable MyArray is NOT an array
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Begin/Else/End/Again Commands
;===============================================================================
X = '| Begin |'
Begin PT = 'N' ; PT is used for testing; normally 'N'
Begin X = X ; Comparison is true
Output X[1 2] ; This will be executed
Output X[3 4] ; This will be executed
Else
Odb 'A' ; This will not be executed
End
End
Begin PT = 'N' ; PT is used for testing; normally 'N'
Begin X <> X ; Comparison is false
Odb 'B' ; This will not be executed
Else
Output X[5 6] ; This will be executed
End
End
Begin PT = 'N' ; PT is used for testing; normally 'N'
XLen = Len X
Counter = 6
Begin ; Loop through the rest
Counter = Counter+
Z = Cols X Counter Counter
Output Z
Again Counter #< XLen ; Stop when we've sent the last char
End
X = 100
Begin 'A' = 'A'
X = X+ ; This will be executed
Begin 'A' = 'A'
X = X+ ; This will be executed
End
Counter = 0
Begin
Counter = Counter+
X = X+ ; This will happen 3 times
Again Counter #< 3
Begin 'A' = 'Z'
X = X- ; This will not be executed
Else
X = X+ ; This will be executed
Begin 1 <> 3
X = X+ ; This will be executed
Else
X = X- ; This will not be executed
End
End
Else
X = X- ; This will not be executed
Begin 'A' = 'A'
X = 'Oops' ; This will not be executed
End
End
If X <> '107' Odb 'C' X
X = 0
Begin
X = X+
Again X #< 10 ; Test at bottom of loop
If X <> 10 Odb 'D' X
X = 0
Begin X #< 11 ; Test at top of loop
X = X+
Again
If X <> 11 Odb 'E' X
Z = 'Test'
X = 0
Begin Z = 'Test' ; Conditional repeat-until
X = X+
Again X #< 12
If X <> 12 Odb 'F' X
Z = 'No Test'
X = 0
Begin Z = 'Test' ; Skipped conditional repeat-until
X = X+
Again X #< 13
If X <> 0 Odb 'G' X
Z = 'Test'
X = 0
Begin Z = 'Test' ; Conditional repeat-until
X = X+
If X = 3 Z = 'No Test' ; Interrupt the loop at the top
Again X #< 14
If X <> 3 Odb 'H' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Break Command
;===============================================================================
If PT = 'N' Output '| Break |'
X = 0
Begin X #< 10 ; Test at top of loop
X = Calc X + 2
If X #= 6 Break
Again
If X <> 6 Odb 1 X
X = 0
Begin
X = Calc X + 2
If X #= 8 Break
Again X #< 10 ; Test at bottom of loop
If X <> 8 Odb 2 X
X = 0
Begin
X = Calc X + 2
If X #= 12 Break ; This will never trigger
Again X #< 10
If X <> 10 Odb 3 X
X = 0
Begin
Inc X
If X #> 4 Break ; Proceeds to the second Again along
Begin
Inc X
Again X #< 4
Again ; Without Break would loop forever
If X <> 5 Odb 4 X
;-------------------------------------------------------------------------------
; The following code would not work because Break looks for an Again
; command somewhere within the same set of Begin/End/Again blocks.
;-------------------------------------------------------------------------------
;X = 15
;Begin X = 15
; X = X+
; If X = 30 Break
; X = X+
;End
;-------------------------------------------------------------------------------
; The following command is "out of context" because it is not in a Begin
; block. If it is uncommented, it will cause a script error.
;-------------------------------------------------------------------------------
;Break
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Calc Command
;===============================================================================
If PT = 'N' Output '| Calc |'
X = Calc 1 + 2 ; Addition
If X <> 3 Odb 1 X
X = Calc ' 3 ' - ' 4 ' ; Subtraction with spurious spaces
If X <> -1 Odb 2 X
X = Calc '#3,000' * 'Number 4' ; Multiplication with lots of noise
If X <> 12000 Odb 3 X
X = Calc 12 / 2 ; Integer division
If X <> 6 Odb 4 X
X = Calc 13 / 2 ; Integer division
If X <> 6 Odb 5 X ; Remainder is discarded
X = Calc 100 / 99 ; Integer division
If X <> 1 Odb 6 X ; Remainder is discarded
X = Calc 999 / 1000 ; Integer division
If X <> 0 Odb 7 X ; Remainder is discarded
X = Calc 100 Highest 10 ; Pick the highest number
If X <> 100 Odb 8 X
X = Calc 200 Lowest 20 ; Pick the lowest number
If X <> 20 Odb 9 X
If X = 20 Z = Calc X * 2 ; A conditional calculation
If Z <> 40 Odb 'A' Z
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The CalcReal Command (see also: Rounding)
;===============================================================================
If PT = 'N' Output '| CalcReal |'
X = CalcReal 1 + 2.14 ; Addition
If X <> 3.14 Odb 1 X
X = CalcReal ' 3.1 ' - ' 4.3 ' ; Subtraction with spurious spaces
If X <> -1.20 Odb 2 X
X = CalcReal '#30.001' * 'XXX 4' 3 ; Lots of non-numeric noise
If X <> 120.004 Odb 3 X
X = Calc 12 / 2 ; Division to 2 decimal places
If X #<> 6.000 Odb 4 X ; Note use of #<> with 3 decimals here
X = CalcReal 13 / -2 ; Division
If X #<> -6.5 Odb 5 X ; Note use of #<> with 1 decimal here
X = CalcReal 100 / 99 2 ; Division to 2 decimal places
If X #<> 1.01 Odb 6 X
X = CalcReal 100 / 99 4 ; Division to 4 decimal places
If X <> 1.0101 Odb '7A' X
X = CalcReal 100 / 99 5 ; Division to 5 decimal places
If X <> 1.01010 Odb '7B' X
X = CalcReal 100 / 99 9 ; Division to 9 decimal places
If X <> 1.010101010 Odb '7C' X
X = CalcReal 100 Highest 100.01 3 ; Pick the highest number
If X <> 100.010 Odb 8 X
X = CalcReal 200. Lowest 20.0 ; Pick the lowest number
If X <> 20.00 Odb 9 X ; Note that X <> 20 would fail
X = CalcReal 200. Lowest 20.0 ; Pick the lowest number
If X #<> 20 Odb 'A' X ; Here the #<> is mixing real/integer
X = CalcReal 200. Lowest 20.0 '0' ; Pick the lowest number
If X <> 20. Odb 'B' X ; Zero decimal places
X = CalcReal 7 / 3 'Float' ; We'll get whatever we can
If X[1 10] <> 2.33333333 Odb 'C' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Call Command
;===============================================================================
If PT = 'N' Output '| Call |'
Call MyProcedure ; Simple call to a procedure
If MyProcedure <> 'Hello' >>
Odb 'B' MyProcedure
If X <> 'Set by MyProcedure' >>
Odb 'C' X
Cntr = 0
Begin
Call AddCntr ; Calling within a loop
Again Cntr #< 5
If Cntr #<> 5 Odb 'D' Cntr
Cntr = 0
Call ProcInProc1 ; A procedure that calls another one
If Cntr #<> 3 Odb 'E' Cntr
X = ''
If X = '' Call ProcInProc2 ; A similar example
If X <> 'AAAAAA' Odb 'F' X
Call ParmProc 'A' '/' 'B' ; Set ParmProc to 'A/B' then call it
If ParmProc <> 'AB' Odb 'G' ParmProc
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Change Command
;===============================================================================
If PT = 'N' Output '| Change |'
X = 'ABCD'
Change X 'BC' 'ZZ' ; Single replacement
If X <> 'AZZD' Odb 1 X
X = 'ABCBCD'
Change X 'BC' 'ZZ' ; Multiple replacements
If X <> 'AZZZZD' Odb 2 X
X = 'ABCD'
Change X 'BC' '' ; Replace with null
If X <> 'AD' Odb 3 X
X = 'ABCD'
Change X 'Z' 'XYZ' ; Replacement text not found
If X <> 'ABCD' Odb 5 X
X = 'ABCD'
Change X '' 'ZZ' ; Replace nothing
If X <> 'ABCD' Odb 6 X
X = ' 1 / 2 / 3 '
Change X ' /' '/' ; This must be done several times
If X <> ' 1/ 2/ 3 ' Odb 7 X ; until the change is complete
X = ' 1 / 2 / 3 '
Change X ' /' '/' 'OnePass' ; Here we say to do it only once
If X <> ' 1 / 2/ 3 ' Odb 8 X
X = 'AABCD'
Change X 'A' 'AA' 'MultiPass' ; If repeated, this would never end!
If X <> 'AAAABCD' Odb 9 X ; Thus, Change only does it once
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The ChangeCase Command
;===============================================================================
If PT = 'N' Output '| ChangeCase |'
X = 'Fred Jones'
Z = ChangeCase X ; Default to uppercase
If Z <> 'FRED JONES' Odb 1 Z
X = 'FRED Jones'
Z = ChangeCase X 'Lowercase' ; Convert to lowercase
If Z <> 'fred jones' Odb 2 Z
X = 'fred jones'
Z = ChangeCase X 'Capitalize' ; Convert to soft caps
If Z <> 'Fred Jones' Odb 3 Z
X = 'FRED jones'
Z = ChangeCase X 'Capitalize' ; Convert to soft caps
If Z <> 'FRED Jones' Odb 5 Z
X = 'FRED jones'
Z = ChangeCase X 'Hardcaps' ; Convert to hard caps
If Z <> 'Fred Jones' Odb 6 Z
X = 'WX-XY123'
Z = ChangeCase X 'Hardcaps' ; Convert to hard caps
If Z <> 'Wx-Xy123' Odb 7 Z
X = 'wx-xy123'
Z = ChangeCase X 'Capitalize' ; Convert to soft caps
If Z <> 'Wx-Xy123' Odb 8 Z ; Same result in this instance
X = 'wx-xy123'
Z = ChangeCase X 'Uppercase' ; Convert to uppercase
If Z <> 'WX-XY123' Odb 9 Z
X = 'Fred Jones'
Z = ChangeCase X[1 4] ; Convert a substring to uppercase
If Z <> 'FRED' Odb 'A' Z
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Cols Command
;===============================================================================
If PT = 'N' Output '| Cols |'
X = 'ABCD' ; Used for all tests
Z = Cols X 2 3 ; Plain Cols command
If Z <> 'BC' Odb 1 Z
Z = Cols X '2' '3' ; Using quoted literals
If Z <> 'BC' Odb 2 Z
Z = Cols X '2' 3 ; Using quoted and unquoted literals
If Z <> 'BC' Odb 3 Z
Z = Cols X 10 99 ; Beyond right edge of data
If Z <> '' Odb 4 Z
Z = Cols X 0 99 ; Zero as starting position means 1
If Z <> 'ABCD' Odb 5 Z
Z = Cols X -1 99 ; Negative starting position means 1
If Z <> 'ABCD' Odb 6 Z
Z = Cols X 1 -1 ; Negative ending position
If Z <> '' Odb 7 Z
Z = Cols X 3 ; Copy a single character
If Z <> 'C' Odb 8 Z
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The CompareControl Command
;===============================================================================
If PT = 'N' Output '| CompareCtrl |'
If 'a' <> 'A' Odb 'ERROR-A' ; They ARE equal because case is ignored
CompareCtrl 'MatchCase'
If 'a' = 'A' Odb 'ERROR-B' ; They are NOT equal now; case matters
CompareCtrl 'IgnoreCase'
If 'z' <> 'Z' Odb 'ERROR-C' ; Back to standard behaviour
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Config Command (see start of script for the actual Config section)
;===============================================================================
If PT = 'N' OutEnd '| Config |' ; Included here for completeness
;===============================================================================
; The Continue Command
;===============================================================================
If PT = 'N' Output '| Continue |'
X = 0
Begin X #< 10 ; Test at top of loop
X = Calc X + 2 ; 2, 4, 6, 8, 10
If X #< 10 Continue ; Jump to the Again
X = X+ ; This makes X equal 11
Again
If X <> 11 Odb 1 X
X = 0
Begin
X = X+ ; 1, 2
If X #= 1 Continue ; Jump to Again the first time only
X = Calc X + 10 ; This makes X equal 12
Again X #< 10 ; Test at bottom of loop
If X <> 12 Odb 2 X
X = 3
Begin
X = X+ ; Now X = 4
If X #= 5 Continue ; This will never trigger
Again X #< 4
If X <> 4 Odb 3 X
X = 10
Begin
X = X+ ; Now X = 11
If X #= 11 Continue ; This will trigger once
Again X <> 11 ; But we stop anyway, since X = 11
If X <> 11 Odb 4 X
X = 0
Begin
Inc X ; 1, 6, 7, 8
If X #> 4 Continue ; Proceeds to the second Again along
Begin
Inc X 2 ; 3, 5
Again X #< 4
Again X #< 8
If X <> 8 Odb 4 X
;-------------------------------------------------------------------------------
; The following usage is somewhat odd, as it is using Continue without an
; If command. If the Begin or Again did not have a condition that could
; fail, the script would loop forever. Continue commands typically have
; an If command before them.
;-------------------------------------------------------------------------------
X = 0
Begin X = 0
Inc X ; Now X = 1
Continue ; Jump to the Again
Inc X 100 ; This is never executed
Again
If X <> 1 Odb 'A' X
;-------------------------------------------------------------------------------
; The following code would not work because Continue looks for an Again
; command somewhere within the same set of Begin/End/Again blocks.
;-------------------------------------------------------------------------------
;X = 3
;Begin X = 3
; X = X+
; If X = 4 Continue
;End
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Dec Command
;===============================================================================
If PT = 'N' Output '| Dec |'
X = 3
Dec X ; Plain decrement
If X <> 2 Odb 'A' X
Dec X 3 ; Decrement by 3
If X <> -1 Odb 'B' X
Dec X -5 ; Negative decrement (equivalent to Inc X 5)
If X <> 4 Odb 'C' X
;-------------------------------------------------------------------------------
; The following would not work because Dec handles only integer values
;-------------------------------------------------------------------------------
; X = 1.3
; Dec X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Done Command (these tests are usually commented out)
;===============================================================================
If PT = 'N' OutEnd '| Done |'
;-------------------------------------------------------------------------------
; Note: Uncommenting any of the following tests will cause every line of
; the input file to be processed, since we will be skipping the rest of
; this script -- including the final Stop command.
;-------------------------------------------------------------------------------
; Done
;
; X = 'Y'
; If X = 'Y' Done
;===============================================================================
; The Else Command (see "The Begin/Else/End/Again Commands" for tests)
;===============================================================================
If PT = 'N' OutEnd '| Else |' ; Included here for completeness
;===============================================================================
; The End Command (see "The Begin/Else/End/Again Commands" for tests)
;===============================================================================
If PT = 'N' OutEnd '| End |' ; Included here for completeness
;===============================================================================
; The Exit Command (see Procedure EnsureOptionEmpty for an example)
;===============================================================================
If PT = 'N' OutEnd '| Exit |' ; Included here for completeness
;===============================================================================
; The Equals Command
;===============================================================================
If PT = 'N' Output '| Equals |'
X = 'ABCD' ; Assignment of a text literal
If X <> 'ABCD' Odb 1 X
X = 3.14 ; Assignment of a numeric literal
If X <> '3.14' Odb 2 X
X = -3.14 ; Assignment of a negative numeric
If X <> '-3.14' Odb 3 X
X = +3.14 ; Superfluous plus sign
If X <> '3.14' Odb 4 X
X = .14 ; Plain decimal numeric
If X <> '.14' Odb 5 X
X = 'AB' 'CD' ; Ordinary concatenation
If X <> 'ABCD' Odb 6 X
X = 'Pi=' 3.14 ; Mixed concatenation
If X <> 'Pi=3.14' Odb 7 X
X = Cols 'ABCD' 2 3 ; Set from a function
If X <> 'BC' Odb 8 X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The FindPosn Command
;===============================================================================
If PT = 'N' Output '| FindPosn |'
X = 'ABBCD' ; Used for all tests
Z = FindPosn X 'B' ; Plain find
If Z <> 2 Odb 1 Z
Z = FindPosn X '1*B' ; First occurrence
If Z <> 2 Odb 2 Z
Z = FindPosn X '2*B' ; Second occurrence
If Z <> 3 Odb 3 Z
Z = FindPosn X '>*B' ; Last occurrence
If Z <> 3 Odb 4 Z
Z = FindPosn X 'BB' 'Include' ; Explicit Include (it's the default)
If Z <> 2 Odb 5 Z
Z = FindPosn X 'BB' 'Exclude' ; Exclude (char position after decap)
If Z <> 4 Odb 6 Z
Z = FindPosn X '-1' ; Char position of last character
If Z <> 5 Odb 7 Z
Z = FindPosn X '-2' ; Second-to-last character
If Z <> 4 Odb 8 Z
Z = FindPosn X '-2' ; Second-to-last character
If Z <> 4 Odb 9 Z
Z = FindPosn X 'Z' ; Not found due to absence
If Z <> 0 Odb 'A' Z
Z = FindPosn X 'b' ; Not found due to case
If Z <> 0 Odb 'B' Z
Z = FindPosn X 'b' 'IgnoreCase' ; Ignoring case
If Z <> 2 Odb 'C' Z
Z = FindPosn X[3 4] 'C' ; Searching a substring
If Z <> 2 Odb 'D' Z
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The If Command (Literal)
;===============================================================================
If PT = 'N' Output '| If Literal |'
X = 'ABCD'
Z = 'ABCDEFG'
If X = '' Odb 1
If X <> 'ABCD' Odb 2
If X > 'ABCD' Odb 3
If X < 'ABCD' Odb 4
If X Len<> 4 Odb 5
If X Len> 4 Odb 6
If X Len< 4 Odb 7
If X ~ 'A' Odb 8
If X ~ 'a' Odb 9 ; Not case-sensitive
If X Longer Z Odb 'A'
If Z Shorter X Odb 'B'
If X SameLen Z Odb 'C'
If X Shorter '' Odb 'D'
If '' Longer X Odb 'E'
If X Longer 1234 Odb 'F'
If X SameLen 123 Odb 'G'
If X[2] <> 'B' Odb 'H'
If 'C' <> X[3] Odb 'I'
If X[2 3] <> 'BC' Odb 'J'
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The If Command (Numeric)
;===============================================================================
If PT = 'N' Output '| If Numeric |'
X = '123'
Z = '123.45'
If X #< '123' Odb 1
If X #> '123' Odb 2
If X #<> '123' Odb 3
If X #<> '123.0' Odb 4
If X #= Z Odb 5
If X #>= Z Odb 6
If Z #<= X Odb 7
If 124 <> X+ Odb 8
If X- #<> 122 Odb 9
If X[2] #<> 2 Odb 'A'
If 23 #<> X[2 3] Odb 'B'
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The If Command (Length)
;===============================================================================
If PT = 'N' Output '| If Length |'
X = 'ABC'
If X Len= 0 Odb 1
If X Len<> 3 Odb 2
If X Len> 3 Odb 3
If X Len>= 4 Odb 5
If X Len< 3 Odb 6
If X Len<= 2 Odb 7
If X[1] Len<> 1 Odb 8
If X[1 2] Len<> 2 Odb 9
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The If Command (Pattern)
;===============================================================================
If PT = 'N' Output '| If Pattern |'
Pattern = 'b[aiu]t'
X = '?'
If 'bat' Matches Pattern X = 'A' ; This will match
If X <> 'A' Odb 'A' X
If 'bit' Matches Pattern X = 'B' ; This will match
If X <> 'B' Odb 'B' X
If 'BUT' Matches Pattern X = 'C' ; This will match (case is ignored)
If X <> 'C' Odb 'C' X
X = 'D'
If 'bet' Matches Pattern X = '' ; This will not match
If X <> 'D' Odb 'D'
X = 'E'
If 'boot' Matches Pattern X = '' ; This will not match
If X <> 'E' Odb 'E'
Pattern = '-*[0-9][0-9]*' ; Pattern matches integer numbers
If '1234' Matches Pattern X = 'F' ; This will match
If X <> 'F' Odb 'F' X
If '1' Matches Pattern X = 'G' ; This will match
If X <> 'G' Odb 'G' X
If '-999' Matches Pattern X = 'H' ; This will match
If X <> 'H' Odb 'H' X
X = 'I'
If '3.14' Matches Pattern X = '' ; No match due to decimal point
If X <> 'I' Odb 'I' X
X = 'J'
If '-' Matches Pattern X = '' ; No match due to no digits
If X <> 'J' Odb 'J' X
X = 'K'
If '' Matches Pattern X = '' ; No match -- it's null
If X <> 'K' Odb 'K' X
X = 'L'
If ' 12 ' Matches Pattern X = '' ; No match due to spaces
If X <> 'L' Odb 'L' X
Pattern = '.Y.'
X = '?'
If 'XYZ' Matches Pattern X = 'M' ; Pattern will match
If X <> 'M' Odb 'M' X
X = '?'
If 'WXYZ' Matches Pattern X = 'N' ; Will not match: length differs
If X <> '?' Odb 'N' X
X = '?'
If 'WXYZ' Comprises Pattern X = 'O' ; This will match (substrings found)
If X <> 'O' Odb 'O' X
X = '?'
If 'ZYXW' Comprises Pattern X = 'P' ; This will match (substrings found)
If X <> 'P' Odb 'P' X
X = '?'
If 'XYZ' Comprises Pattern X = 'Q' ; This will also match
If X <> 'Q' Odb 'Q' X
X = '?'
If 'ayc' Comprises Pattern X = 'R' ; Case is not important
If X <> 'R' Odb 'Q' X
;-------------------------------------------------------------------------------
; The next two demonstrations use the dynamic comparator ($Compare). This is
; not frequently used, but is handy if you want to create a script that can,
; for example, process queries loaded from a file (using SetFromFile).
;-------------------------------------------------------------------------------
$Compare = '#>'
If 3 $Compare 4 Odb 'X'
$Compare = 'Matches'
If '$39.95' $Compare '\$[0-9][0-9]*\.[0-9][0-9]' X = 'Y'
If X <> 'Y' Odb 'Y' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Inc Command
;===============================================================================
If PT = 'N' Output '| Inc |'
X = 0
Inc X ; Plain increment
If X <> 1 Odb 'A' X
Inc X 3 ; Increment by 3
If X <> 4 Odb 'B' X
Inc X -5 ; Negative increment (equivalent to Dec X 5)
If X <> -1 Odb 'C' X
;-------------------------------------------------------------------------------
; The following would not work because Inc handles only integer values.
;-------------------------------------------------------------------------------
; X = 1.3
; Inc X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Insert Command
;===============================================================================
If PT = 'N' Output '| Insert |'
X = 'abcd'
Insert X 'c' 'Z' ; Insert one character at decap
If X <> 'abZcd' Odb 1 X
X = 'abcd'
Insert X 'b' 'Z' 'Exclude' ; Insert one character after
If X <> 'abZcd' Odb 2 X
X = 'abcd'
Insert X 'c' 'ZZ' ; Insert multiple characters at decap
If X <> 'abZZcd' Odb 3 X
X = 'abcd'
Insert X 'c' 'ZZ' 'Exclude' ; Insert multiple characters after
If X <> 'abcZZd' Odb 4 X
X = 'abcccd'
Insert X '2*c' 'Z' ; Insert at occurrence count
If X <> 'abcZccd' Odb 5 X
X = 'abcd'
Insert X '' 'Z' ; Insert at front (same as an append)
If X <> 'Zabcd' Odb 6 X
X = 'abcccd'
Insert X '2*c' 'Z' 'Exclude' ; Insert after occurrence count
If X <> 'abccZcd' Odb 7 X
X = 'abcd'
Insert X '2' 'Z' ; Insert positional
If X <> 'aZbcd' Odb 8 X
X = 'abcd'
Insert X '-2' 'ZZ' ; Insert at second-to-last char
If X <> 'abZZcd' Odb 9 X
X = 'abcd'
Insert X '-1' 'ZZ' ; Insert at last char
If X <> 'abcZZd' Odb 'A' X
X = 'abcd'
Insert X 'C' 'Z' ; Failed search due to case
If X <> 'abcd' Odb 'B' X
X = 'abcd'
Insert X 'C' 'Z' 'IgnoreCase' ; Adjusted for case
If X <> 'abZcd' Odb 'C' X
X = 'abcd'
Insert X 'C' 'Z' 'Exclude IgnoreCase' ; Adjusted for case; insert after
If X <> 'abcZd' Odb 'D' X
X = ''
Insert X 'C' 'Z' ; Failed search due to null source
If X <> '' Odb 'E' X
X = ''
Insert X '' 'Z' ; Adjusted with null decap
If X <> 'Z' Odb 'F' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The KeepChar Command
;===============================================================================
If PT = 'N' Output '| KeepChar |'
X = 'ABC-123-abc-A'
KeepChar X '/A' ; Keep single char
If X <> 'AA' Odb 1 X
X = 'ABC-123-abc-A'
KeepChar X '/AZ' ; Keep range of chars
If X <> 'ABCA' Odb 2 X
X = 'ABC-123-abc-A'
KeepChar X '/AZ/-' ; Keep range and single char
If X <> 'ABC---A' Odb 3 X
X = 'ABC-123-abc-A'
KeepChar X '/AZ/09' ; Keep two ranges
If X <> 'ABC123A' Odb 4 X
X = 'ABC-123-abc-A'
KeepChar X '///AZ///09///' ; As before, with superfluous delims
If X <> 'ABC123A' Odb 5 X
X = 'ABC-123-abc-A'
KeepChar X '***AZ***09***' ; As before, with different delims
If X <> 'ABC123A' Odb 6 X
X = 'A-1-a-A'
KeepChar X '/AZ/az/-' ; Keep letters and dashes
If X <> 'A--a-A' Odb 7 X
X = 'A-1-a-A'
KeepChar X '/ZA/za/-' ; Mix up the order of ranges
If X <> 'A--a-A' Odb 8 X
X = 'Give me $199.00, please!' ; Keep cash values only
KeepChar X '/$/./09'
If X <> '$199.00' Odb 9 X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Len Command
;===============================================================================
If PT = 'N' Output '| Len |'
X = 'ABCD'
Z = Len X
If Z <> 4 Odb 1 Z ; Simple measurement
X = ''
Z = Len X
If Z <> 0 Odb 2 Z ; A null is 0 characters long
X = ''
Y = 'DEF'
Z = Len X 'ABC' X Y 'GHI' X ; Measuring concatenated values
If Z <> 9 Odb 3
If PT = 'N' OutNull ; End of this test
;===============================================================================
; Literals
;===============================================================================
If PT = 'N' OutEnd '| Literals |'
X = $78$79$7A
If X <> 'xyz' Odb 1 X
X = #097#098#099
If X <> 'abc' Odb 2 X
X = $20#32'Lit'#101#114'a'$6c's '
If X <> ' Literals ' Odb 3 X
X = #32'Lit'$65$72'als '
If X <> ' Literals ' Odb 4 X
X = 'Literal' $0A $0D ; Both of these: 'Literal' followed
Y = 'Literal' #010 #013 ; by Carriage Return and Linefeed
If X <> Y Odb 5 X
X = 'Literal'$A#13 ; Both of these: 'Literal' followed
Y = 'Literal'#10$D ; by Carriage Return and Linefeed
If X <> Y Odb 6 X
X = Len $0D$0A #10#13 ; Encoded literals with a function
If X <> 4 Odb 7 X
X = $Success ; Note that $ doesn't always mean hex
If 'YN' ~ X Odb 8 X
;-------------------------------------------------------------------------------
; The following is a nearly incomprehensible mess and is not typical of the
; way you normally define a literal in a script. However, it does work.
;-------------------------------------------------------------------------------
Vertibar = '|' ; Carriage Return and Linefeed
X = Vertibar $20'Lit'#101#114'a'$6c's'#032#32$20' ' Vertibar
If X <> '| Literals |' Odb 9 X
;-------------------------------------------------------------------------------
; The following lines, if uncommented, will evoke an error message.
;-------------------------------------------------------------------------------
; X = $$0A$0D ; Doubled-up $
; X = ##10#13 ; Doubled-up #
; X = $0A$0D$ ; Spurious $ at end of line
; X = #10#13# ; Spurious # at end of line
; X = $0A0D ; Missing $ before the $0D
; X = $0A$0P ; $0P is not proper hex
; X = #256 ; 256 exceeds range of 0 to 255
;===============================================================================
; The LookupFile and Lookup Commands
;===============================================================================
If PT = 'N' OutEnd '| LookupFile |'
LookupFile 'OneTwo' 'LufSample01.txt' ; Key Field 1; Data Field 2
LookupFile '1 & 3' 'LufSample01.txt' 1 3 ; Key Field 1; Data Field 3
LookupFile '3 & 2' 'LufSample01.txt' 3 2 ; Key Field 3; Data Field 2
LookupFile 'OneTwo' 'LufSample01.txt' 3 4 ; Ignored: 'OneTwo' already exists
If PT = 'N' Output '| Lookup |'
X = Lookup 'CAT' 'OneTwo' ; Look up 'CAT'
If $Success <> 'Y' Odb 1
If X <> 'Kitty' Odb 2 X
X = Lookup 'Car' 'OneTwo' ; This will fail due to case
If $Success <> 'N' Odb 3 ; The file has 'CAR', not 'Car'
X = Lookup 'Car' 'OneTwo' 'IgnoreCase' ; Case problem fixed
If $Success <> 'Y' Odb 4
If X <> 'Vehicle' Odb 5 X
X = Lookup 'ThisIsField1' '1 & 3' ; Key Field 1; Data Field 3
If $Success <> 'Y' Odb 6
If X <> 'ThisIsField3' Odb 7 X
X = Lookup 'ThisIsField3' '3 & 2' ; Key Field 3; Data Field 2
If $Success <> 'Y' Odb 6
If X <> 'ThisIsField2' Odb 8 X
Z = 'OneTwo' ; Save a bit of typing
X = Lookup 666 Z ; Key Field 1; Data Field 2
If $Success = 'N' Odb 9
If X <> $35$35$35 Odb 'A' X ; $35$35$35 = '555'
X = Lookup 333 Z ; Key Field 1; Data Field 2
If $Success = 'N' Odb 'B'
If X <> 222 Odb 'C' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The MassChange Command
;===============================================================================
If PT = 'N' Output '| MassChange |'
LookupFile 'TwoOne' 'LufSample01.txt' 2 1 ; Key Field 2; Data Field 1
X = 'CAR CAT'
MassChange X 'OneTwo' ; Translating one way
If X <> 'Vehicle Kitty' Odb '1A' X
MassChange X 'TwoOne' ; Translating back to original
If X <> 'CAR CAT' Odb '1B' X
X = 'CAR Cat'
MassChange X 'OneTwo' ; Note that default is 'MatchCase'
If X <> 'Vehicle Cat' Odb '2A' X ; Thus, 'Cat' isn't changed
X = 'Car Cat'
MassChange X 'OneTwo' 'IgnoreCase' ; This time we use 'IgnoreCase'
If X <> 'Vehicle Kitty' Odb '2B' X
X = 'abcd'
MassChange X 'OneTwo' ; Character remapping (this Lookup
If X <> 'ABCd' Odb '3' X ; table only defines 'a', 'b', 'c')
X = 'A B C'
MassChange X '1 & 3' 'IgnoreCase' ; Phonetic character remapping
If X <> 'Ay Bee See' Odb '4' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Numeric Command
;===============================================================================
If PT = 'N' Output '| Numeric |'
Z = 123
X = Numeric Z ; '123' is indeed numeric
If X <> 'Y' Odb 'A' X
Z = 'Woof'
X = Numeric Z ; That wasn't numeric
If X <> 'N' Odb 'B1' X
Z = ''
X = Numeric Z ; Nulls aren't considered numeric
If X <> 'N' Odb 'B2' X
Z = '-'
X = Numeric Z ; A minus sign isn't a numeric
If X <> 'N' Odb 'B3' X
Z = '12A34' ; Note the embedded letter
X = Numeric Z ; So this isn't numeric
If X <> 'N' Odb 'B4' X
Z = 'A1234' ; Note the letter in front
X = Numeric Z ; So this isn't numeric
If X <> 'N' Odb 'B5' X
Z = '1234A' ; Note the letter at the end
X = Numeric Z ; So this isn't numeric
If X <> 'N' Odb 'B6' X
Z = 3.14159
X = Numeric Z ; By default, we only accept integers
If X <> 'N' Odb 'C' X
Z = '3.14159'
X = Numeric Z 'Yes' ; Now will we accept real numbers
If X <> 'Y' Odb 'D1' X
Z = '3.14.159' ; Note the extra decimal point
X = Numeric Z 'Yes' ; So this won't be numeric
If X <> 'N' Odb 'D2' X
Z = '-9999'
X = Numeric Z 'No' ; Negative numbers are numeric
If X <> 'Y' Odb 'E1' X
Z = '- 9999' ; Note the embedded space
X = Numeric Z 'No' ; So this isn't numeric
If X <> 'N' Odb 'E2' X
Z = '+99.99'
X = Numeric Z 'Yes' ; A leading + sign is ignored
If X <> 'Y' Odb 'F' X
If PT = 'N' OutNull
;===============================================================================
; The OutCSV Command
;===============================================================================
;
; The following is included for completeness but is not a good demonstration
; of the powerful OutCSV command. For a better demonstration, please see the
; ScrOutCSVDemo script.
;
;-------------------------------------------------------------------------------
OutCSV 'QuoteChar |' 'Control'
OutCSV 'MinWidth 17' 'Control'
OutCSV 'MaxWidth 17' 'Control'
OutCSV ' ' 'Init'
OutCSV ' OutCSV Max' 'Quoted'
OutCSV '' 'Done'
OutCSV ' ' 'Init'
OutCSV ' OutCSV Min ' 'Quoted'
OutCSV '' 'Done'
;===============================================================================
; The Odb Command | Yes, this looks a bit ugly, as headers go, |
; The Output Command | but people who are consulting this file for |
; The OutNull Command | examples will probably search for a string |
; The OutEnd Command | in the form "The [X] Command". |
;===============================================================================
If PT = 'N' Odb ' Odb '
X = 'Out'
Y = 'put'
If PT = 'N' Output '| ' X Y ' |' ; Concatenated values
If PT = 'N' OutNull ; Move to next line
If PT = 'N' Output '| OutNull |' ; Included here for completeness
If PT = 'N' OutNull ; Move to next line
Z = 'OutEnd'
If PT = 'N' OutEnd '| ' Z ' |' ; Concatenated values
;===============================================================================
; The Otherwise Command
;===============================================================================
If PT = 'N' OutEnd '| Otherwise |'
X = 3
If X = 4 Odb 'A' X ; This is false, so it will not happen
Otherwise X = 999 ; Since it was false, this WILL happen
If X <> 999 Odb 'B' X
Cntr = 3
If Cntr = 3 Call AddCntr ; This is true, so it will happen
Otherwise Cntr = 999 ; This will NOT happen
If Cntr <> 4 Odb 'C' Cntr
Cntr = 777
If Cntr = 3 Call AddCntr ; This is false, so it will not happen
Otherwise Cntr = 888 ; Thus, this WILL happen
If Cntr <> 888 Odb 'D' Cntr
Cntr = 3
If Cntr = 3 Call AddCntr ; This is true, so it will happen
Otherwise Call AddCntr2 ; Thus, this will NOT happen
If Cntr <> 4 Odb 'E' Cntr
Cntr = 4
If Cntr = 3 Call AddCntr ; This is false, so it will not happen
Otherwise Call AddCntr2 ; Thus, this WILL happen
If Cntr <> 6 Odb 'F' Cntr
;-------------------------------------------------------------------------------
; The next lines demonstrate that comments and null lines aren't counted when
; applying the rule that an Otherwise must immediately follow an If command.
;-------------------------------------------------------------------------------
Cntr = 4
If Cntr = 3 Call AddCntr ; This is false, so it will not happen
;
; Visit www.tc123.com if you'd like to see the personal home page
; of the lead programmer at Pinnacle Software.
;
Otherwise Call AddCntr2 ; Thus, this WILL happen
If Cntr <> 6 Odb 'F' Cntr
;-------------------------------------------------------------------------------
; If the next lines are uncommented it will cause an error, since an Otherwise
; command must appear on a line immediately following an If command (comments
; and null lines don't count, of course).
;-------------------------------------------------------------------------------
; X = 3
; Otherwise OutEnd 'Stand-alone Otherwise'
;===============================================================================
; The OutRuler Command (actual command commented out to keep output tidy)
;===============================================================================
X = '| OutRuler |'
If PT = 'N' OutEnd X
; OutRuler X
;===============================================================================
; The Overlay Command
;===============================================================================
If PT = 'N' Output '| Overlay |'
X = 'abcd'
Overlay X '3' 'Z' ; Positional overlay
If X <> 'abZd' Odb 1 X
If $Success = 'N' Odb 2
X = 'abcd'
Overlay X '<*b' 'ZZ' ; Overlay first occurrence
If X <> 'aZZd' Odb 3 X
If $Success <> 'Y' Odb 4
X = 'abcd'
Overlay X '<*b' 'ZZ' 'Exclude' ; Exclude found text
If X <> 'abZZ' Odb 5 X
If $Success Is 'n' Odb 6
X = 'abcd'
Overlay X 'w' 'ZZ' ; Failed search
If X <> 'abcd' Odb 7 X
If $Success Is 'y' Odb 8
X = 'abbb'
Overlay X '2*b' 'ZZ' ; Overlay second occurrence
If X <> 'abZZ' Odb 9 X
X = 'abbb'
Overlay X '>*b' 'Z' ; Overlay last occurrence
If X <> 'abbZ' Odb 'A' X
X = 'abbb'
Overlay X '2*b' 'ZZ' 'Exclude' ; As above, but exclude found text
If X <> 'abbZZ' Odb 'B' X
X = 'abcd'
Overlay X '' 'ZZ' ; Overlay from beginning
If X <> 'ZZcd' Odb 'C' X
X = 'abcd'
Overlay X 'd' 'ZZZ' ; Extend length of variable
If X <> 'abcZZZ' Odb 'D' X
X = 'abcd'
Overlay X 'B' 'ZZ' ; Failed due to case
If X <> 'abcd' Odb 'E' X
X = 'abcd'
Overlay X 'B' 'ZZ' 'IgnoreCase' ; Adjusted for case
If X <> 'aZZd' Odb 'F' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Padded Command
;===============================================================================
If PT = 'N' Output '| Padded |'
X = Padded 'AB' 4 ; Defaults are 'Right' and ' '
If X <> 'AB ' then Odb 1 X ; Use of "then" is non-standard
X = Padded 'CD' 5 'Left'
If X <> ' CD' then Odb 2 X
X = Padded 'EF' 6 'Center'
If X <> ' EF ' then Odb 3 X
X = Padded 'XYZ' 7 'Left' 'x'
If X <> 'xxxxXYZ' then Odb 4 X
X = ''
X = Padded X '3' 'Left' 'x'
If X <> 'xxx' then Odb 5 X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Parse Command
;===============================================================================
If PT = 'N' Output '| Parse |'
Z = 'ABCD'
X = Parse Z 'B' 'D' ; Plain decapsulators
If X <> 'c' Odb 1 X ; If comparisons are case-insensitive
Z = 'ABBCCDD'
X = Parse Z '2*B' '2*D' ; Second occurrence, "From" and "To"
If X <> 'CCD' Odb 2 X
Z = 'ABBCCDD'
X = Parse Z '2*B' '2*D' 'Include' ; As above, but Included
If X <> 'BCCDD' Odb 3 X
Z = 'ABBCCDD'
X = Parse Z '<*b' '>*d' 'IgnoreCase' ; First and last, case ignored
If X <> 'BCCD' Odb 4 X
Z = 'ABCD'
X = Parse Z '-3' '-2' ; Counting from the right
If X <> 'BC' Odb 5 X
Z = 'ABCD'
X = Parse Z '-3' '' ; Null "To" decapsulator
If X <> 'BCD' Odb 6 X
Z = 'ABCD'
X = Parse Z '' '-2' ; Null "From" decapsulator
If X <> 'ABC' Odb 7 X
Z = 'ABCD'
X = Parse Z '' '-2' ; Null "From" decapsulator
If X <> 'ABC' Odb 8 X
Z = 'ABCD'
X = Parse Z '' '' ; Both decapsulators null
If X <> 'ABCD' Odb 9 X
Z = 'John,Aloysius,Smith'
Name1 = Parse Z '' ',' 'Cut'
Name2 = Parse Z '' ',' 'Cut'
Name3 = Parse Z '' ',' 'Cut' ; This should fail
Name4 = Parse Z '' ',' 'Cut Relaxed' ; This should work
If Name1 <> 'John' Odb 'A' X
If Name2 <> 'Aloysius' Odb 'B' X
If Name3 <> '' Odb 'C' X
If Name4 <> 'Smith' Odb 'D' X
Z = 'ABCD'
X = Parse Z 'b' 'D' ; Fail due to case
If X <> '' Odb 'E' X
Z = 'ABCD'
X = Parse Z 'b' 'D' 'IgnoreCase' ; Adjust for case
If X <> 'C' Odb 'F' X
Z = 'AB12AB34AB56AB78'
X = Parse Z 'B' '@*B' ; From first 'B' to following 'B'
If X <> '12A' Odb 'G1' X
X = Parse Z '2*B' '@*B' ; From second 'B' to following 'B'
If X <> '34A' Odb 'G2' X
X = Parse Z '3*B' '@*AB' ; From third 'B' to following 'AB'
If X <> '56' Odb 'G3' X
Z = 'AB,CD,EF'
X = Parse Z '' '@*,' ; From start, to following comma
If X <> 'AB' Odb 'G4' X
Z = ',CD,EF' ; Note that first field is null
X = Parse Z '' '@*,' ; From start, to following comma
If X <> '' Odb 'G5' X
Z = ',CD,EF'
X = Parse Z ',' '@*,' ; From first to second comma
If X <> 'CD' Odb 'G6' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Plural Command
;===============================================================================
If PT = 'N' Output '| Plural |'
N = 1
X = Plural 'cat' N
If X <> 'cat' Odb 'A' X
N = 2
X = Plural 'cat' N
If X <> 'cats' Odb 'B' X
N = 0
X = Plural 'cat' N
If X <> 'cats' Odb 'C' X
N = ' 1.5 ' ; Note that spaces are ignored
X = Plural 'cat' N 'No' ; Not preserving length (default)
If X <> 'cats' Odb 'D' X
N = 1
X = Plural 'cat' N 'Yes' ; We're preserving length
If X <> 'cat ' Odb 'E1' X
N = 2
X = Plural 'cat' N 'Yes' ; We're preserving length
If X <> 'cats' Odb 'E2' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The ParseName Command
;===============================================================================
If PT = 'N' Output '| Procedure |'
Z = 'Miss Mary Jane Smith, Esq.'
ParseName Z 'No' addform first middle last suffix
If addform <> 'Miss' Odb 'A1' addform
If first <> 'Mary' Odb 'A2' first
If middle <> 'Jane' Odb 'A3' middle
If last <> 'Smith' Odb 'A4' last
If suffix <> 'Esq.' Odb 'A5' suffix
Z = 'Fred Jones III'
ParseName Z 'No' addform first middle last suffix
If addform <> '' Odb 'B1' addform
If first <> 'Fred' Odb 'B2' first
If middle <> '' Odb 'B3' middle
If last <> 'Jones' Odb 'B4' last
If suffix <> 'III' Odb 'B5' suffix
Z = 'Elvis "The Pelvis" Presley'
ParseName Z 'No' addform first middle last suffix
If addform <> '' Odb 'C1' addform
If first <> 'Elvis' Odb 'C2' first
If middle <> '"The Pelvis"' Odb 'C3' middle
If last <> 'Presley' Odb 'C4' last
If suffix <> '' Odb 'C5' suffix
Z = 'Whizzco Inc.'
ParseName Z 'No' addform first middle last suffix ; Company-detect disabled
If addform <> '' Odb 'D1' addform
If first <> 'Whizzco' Odb 'D2' first
If middle <> '' Odb 'D3' middle
If last <> 'Inc' Odb 'D4' last
If suffix <> '' Odb 'D5' suffix
Z = 'Whizzco Inc.'
ParseName Z 'Yes' addform first middle last suffix ; Company-detect enabled
If addform <> '' Odb 'E1' addform
If first <> 'Whizzco Inc.' Odb 'E2' first
If middle <> '' Odb 'E3' middle
If last <> '' Odb 'E4' last
If suffix <> '' Odb 'E5' suffix
Z = 'Mr. Robert J. L. Van de Graff the third'
ParseName Z 'Yes' addform first middle last suffix
If addform <> 'Mr.' Odb 'F1' addform
If first <> 'Robert' Odb 'F2' first
If middle <> 'J. L.' Odb 'F3' middle
If last <> 'Van de Graff' Odb 'F4' last
If suffix <> 'the third' Odb 'F5' suffix
Z = 'Aloysius Katz'
ParseName Z 'Yes' addform first middle last suffix
If addform <> '' Odb 'G1' addform
If first <> 'Aloysius' Odb 'G2' first
If middle <> '' Odb 'G3' middle
If last <> 'Katz' Odb 'G4' last
If suffix <> '' Odb 'G5' suffix
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Procedure Command (procedures traditionally go at the end of a script)
;===============================================================================
If PT = 'N' Output '| Procedure |'
Procedure MyProcedure
MyProcedure = 'Hello' ; Set the var named after the procedure
X = 'Set by MyProcedure' ; Set some other variable
If MyProcedure <> 'Hello' >>
Odb 'A' MyProcedure
End
;Procedure MyProcedure ; If you uncomment these lines it will
; MyProcedure = 'Hello, world!' ; cause an error, since you can only have
;End ; one procedure with a given name
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Que Command
;===============================================================================
If PT = 'N' Output '| Que |'
X = Que 3 = 3 ; This is obviously true
If X <> 'Y' Odb 'A' X
X = Que 3 = 4 ; This is obviously false
If X <> 'N' Odb 'A' X
X = Que 'a' = 'A' ; Case is ignored by default
If X <> 'Y' Odb 'C' X
X = Que ' a ' = 'A' ; The spaces make this false
If X <> 'N' Odb 'D' X
X = Que ' a ' Is 'A' ; Is comparator fixes the space problem
If X <> 'Y' Odb 'E' X ; and serves up a koan for Ayn Rand fans
X = Que 'a' = 'A' 'MatchCase' ; Now case must match
If X <> 'N' Odb 'F' X
X = Que 'a3' Matches '[A-Z][1-9]' ; Case is ignored, so this is true
If X <> 'Y' Odb 'G' X
X = Que 'a3' Matches '[A-Z][1-9]' >> ; This test will be false, because we
'MatchCase' ; are requesting case-sensitivity
If X <> 'N' Odb 'H' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Rounding Command
;===============================================================================
;-------------------------------------------------------------------------------
; Note: Turning Rounding off (i.e. setting it to 'No') is NOT RECOMMENDED.
; Please see the scripting manual for an explanation.
;-------------------------------------------------------------------------------
If PT = 'N' Output '| Rounding |'
Rounding 'No' ; Turn off rounding
X = CalcReal 17.568 / 3 '2' ; 2 decimals; actual answer is 5.856
If X[1 4] <> 5.85 Odb 1 X ; We simply truncated the answer
Rounding 'Yes' ; Turn on rounding (default)
X = CalcReal 17.568 / 3 '2' ; 2 decimals; actual answer is 5.856
If X <> 5.86 Odb 2 X
Rounding 'No' ; Turn rounding off again
X = CalcReal 17.568 / 3 '2' ; 2 decimals; actual answer is 5.856
If X[1 4] <> 5.85 Odb 3 X ; We simply truncated the answer again
X = CalcReal 10.009 * 9 1 ; Actual answer is 90.081
If X[1 4] <> 90.0 Odb '4A' X ; But we're just truncating
Rounding 'Yes'
X = CalcReal 10.009 * 9 1 ; Actual answer is 90.081
If X <> 90.1 Odb '4B' X ; Rounding-up gives a different answer
X = CalcReal 10.009 * 9 2 ; Actual answer is 90.081
If X <> 90.08 Odb '4C' X ; Rounding-up 2 places this time
;-------------------------------------------------------------------------------
; In the next example we are using "Float". This calculation can actually
; generate the answer 90.0810000000000128 -- which is very close to the
; right answer, but contains some "noise". Whenever you use "Float", you
; should be aware that when computer calculations are taken to the limit
; of the software's precision, it can result in a miniscule inaccuracy.
;-------------------------------------------------------------------------------
X = CalcReal 10.009 * 9 'Float' ; Get whatever decimal places we can
If X[1 5] <> 90.08 Odb '4D' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The ScanFollow Command
;===============================================================================
If PT = 'N' Output '| ScanFollow |'
ScanList = '/A/Apple/B/Badger/C/Cat/D/Dog'
X = ScanFollow 'A' ScanList ; Look up 'A'
If X <> 'Apple' Odb 'A' X
X = ScanFollow 'Z' ScanList ; Look up 'Z' (not found)
If X <> '' Odb 'B' X ; Default "Not Found" value is null
X = ScanFollow 'Z' ScanList 'Moose' ; Look up 'Z' (not found)
If X <> 'Moose' Odb 'C' X ; "Not Found" value returned
X = ScanFollow 'a' ScanList 'Pig' 'MatchCase' ; Not found due to case
If X <> 'Pig' Odb 'D' X ; Returns "Not Found" value
X = ScanFollow 'Dog' ScanList 'Cow' ; Nothing follows 'Dog'
If X <> 'Cow' Odb 'E' X ; We'll get the "Not Found" value
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The ScanPosn Command
;===============================================================================
If PT = 'N' Output '| ScanPosn |'
Source = 'Duck Duck Goose Cat Moose'
ScanList = '/Elk/Duck/Cat'
ScanPosn p1 p2 Source ScanList ; 'Any' scan
If $Success = 'N' Odb 1
If p1 <> 1 Odb 'A' p1
If p2 <> 4 Odb 'B' p2
Source = 'Cow Scowl Cowboy'
ScanList = '/Cow'
ScanPosn p1 p2 Source ScanList 'First' ; 'First' scan
If $Success = 'N' Odb 2
If p1 <> 1 Odb 'C' p1
If p2 <> 3 Odb 'D' p2
Source = 'MegaWhizco International'
ScanList = '*CO*WHIZCO*MEGAWHIZ' ; Asterisk used as delimiter
ScanPosn p1 p2 Source ScanList 'Last' ; 'Last' scan, with "best-match"
If $Success <> 'Y' Odb 3
If p1 <> 5 Odb 'E' p1
If p2 <> 10 Odb 'F' p2
ScanPosn p1 p2 'Woof' '/Dog/Cat' ; No string will be found
If $Success <> 'N' Odb 4
If p1 <> 0 Odb 'G' p1
If p2 <> 0 Odb 'H' p2
X = 'Cow Cat Dog'
Y = '/COW/CAT/DOG'
ScanPosn p1 p2 X Y 'Last MatchCase' ; No string found due to case
If $Success <> 'N' Odb 5
If p1 <> 0 Odb 'I' p1
If p2 <> 0 Odb 'J' p2
ScanPosn p1 p2 X Y 'Last IgnoreCase' ; Case problem explicitly solved
If $Success = 'N' Odb 6
If p1 <> 9 Odb 'K' p1
If p2 <> 11 Odb 'L' p2
Source = 'MegaWhizco International'
ScanList = '\CO\WHIZCO\MEGAWHIZ' ; Backslash used as delimiter
ScanPosn p1 p2 Source ScanList 'First' ; 'First' scan, with "best-match"
If $Success <> 'Y' Odb 7
If p1 <> 1 Odb 'M' p1
If p2 <> 8 Odb 'N' p2
X = 'Kitty Cats Are Cool'
Y = '/c.t/co*l'
ScanPosn p1 p2 X Y 'First RegExp' ; 'First' with regular expression
If $Success = 'N' Odb 8
If p1 <> 7 Odb 'O' p1
If p2 <> 9 Odb 'P' p2
ScanPosn p3 p4 X Y 'Last RegExp' ; 'Last' with regular expression
If $Success = 'N' Odb 9
If p3 <> 16 Odb 'Q' p3
If p4 <> 19 Odb 'R' p4
X = '$398.00! Give me $199.00 2 times!'
Y = '@\$[0-9][0-9]*\.[0-9][0-9]' ; Pattern for a currency value
ScanPosn p1 p2 X Y 'RegExp Last'
If $Success = 'N' Odb 10
If p1 <> 18 Odb 'S' p1
If p2 <> 24 Odb 'T' p2
X = Cols X p1 p2 ; Extract the currency value we found
If X <> '$199.00' Odb 'U' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The SetFromFile Command
;===============================================================================
If PT = 'N' Output '| SetFromFile |'
X = SetFromFile 'ScrExercise.txt' ; This script file
If X[1 5] <> ';====' Odb 1 X ; The first comment line
If $Success <> 'Y' Odb 2
X = SetFromFile 'NoSuchFile.txt' ; Non-existent file
If X <> '' Odb 3 X
If $Success <> 'N' Odb 4
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The SplitCSV Command
;===============================================================================
If PT = 'N' Output '| SplitCSV |'
A = '"Cat","Dog","Cow"'
X = SplitCSV A '/'
If X <> 'Cat/Dog/Cow' Odb 'A' X
A = '"Fred ""Wonderdude"" Smith";123.45;"416-555-1212"'
X = SplitCSV A '@' ';'
If X <> 'Fred "Wonderdude" Smith@123.45@416-555-1212' Odb 'B' X
A = '1,2,3'
X = SplitCSV A
Test = 1 #13 2 #13 3
If X <> Test Odb 'C' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; The Stop Command (included for completeness -- used at end of script)
;===============================================================================
If PT = 'N' OutEnd '| Stop |' ; Included here for completeness
;===============================================================================
; The TrimChar Command
;===============================================================================
If PT = 'N' Output '| TrimChar |'
X = ' xxx///yyy zzz/// '
TrimChar X
If X <> 'xxx///yyy zzz///' Odb 1 X
X = ' xxx///yyy zzz/// '
TrimChar X 'L '
If X <> 'xxx///yyy zzz/// ' Odb 2 X
X = ' xxx///yyy zzz/// '
TrimChar X 'R '
If X <> ' xxx///yyy zzz///' Odb 3 X
X = ' xxx///yyy zzz/// '
TrimChar X 'B '
If X <> 'xxx///yyy zzz///' Odb 4 X
X = ' xxx///yyy zzz/// '
TrimChar X 'A '
If X <> 'xxx///yyyzzz///' Odb 5 X
X = ' xxx///yyy zzz/// '
TrimChar X 'B Ay'
If X <> 'xxx/// zzz///' Odb 6 X
X = ' xxx///yyy zzz/// '
TrimChar X 'A Az'
If X <> 'xxx///yyy///' Odb 7 X
X = ' xxx///yyy zzz/// '
TrimChar X 'M/'
If X <> ' xxx/yyy zzz/ ' Odb 8 X
X = ' xxx///yyy zzz/// '
TrimChar X 'B M/'
If X <> 'xxx/yyy zzz/' Odb 9 X
X = ' xxx///yyy zzz/// '
TrimChar X 'MxMyMzM/'
If X <> ' x/y z/ ' Odb 'A' X
X = ' xxx///yyy zzz/// '
TrimChar X 'B Lx' ; The Lx will not accomplish anything
If X <> 'xxx///yyy zzz///' Odb 'B' X
X = ' xxx///yyy zzz/// '
TrimChar X 'B ' ; We address the simultaneity issue
TrimChar X 'Lx' ; by doing two commands in a row
If X <> '///yyy zzz///' Odb 'C' X
If PT = 'N' OutNull ; End of this test
;===============================================================================
; We're only reading in one line from input, so we can move to the next
; parsing step (i.e. FileDone).
;===============================================================================
NextStep
;===============================================================================
; Subroutines
;===============================================================================
; It's a good idea to put a Done command in front of all the Procedure
; definitions, which are usually placed at the end of the script. For small
; files the difference in speed is negligible, but if you are processing a
; huge file it can save you a few seconds.
;-------------------------------------------------------------------------------
Done
Procedure AddCntr
Inc Cntr
End
Procedure AddCntr2
Inc Cntr 2
End
Procedure ProcInProc1
Begin
Call AddCntr
Again Cntr #< 3
End
Procedure ProcInProc2
Begin X Len< 6
Call AddCntr
X = X 'A'
Again
End
Procedure ParmProc
TrimChar ParmProc 'A/'
End
Procedure EnsureOptionEmpty
Caption = Parse EnsureOptionEmpty '' #13 'Cut'
TrimChar EnsureOptionEmpty 'B '
if EnsureOptionEmpty = '' Exit
TrimChar Caption 'A&'
Stop 'Please clear your ' Caption ' input box before running this script'
End